﻿Imports Microsoft.Xna.Framework
Imports Microsoft.Xna.Framework.Graphics
Imports System.Collections.Concurrent
Imports Runa.Foundation.Messaging

Namespace Global.Runa.UI.Threading

    Public MustInherit Class DispatcherObject

        Private _dispatcher As Dispatcher = Dispatcher.CurrentDispatcher

        Public ReadOnly Property Dispatcher As Dispatcher
            Get
                Return Me._dispatcher
            End Get
        End Property

        Public Function CheckAccess() As Boolean
            Dim dispatcher As Dispatcher = Me._dispatcher
            If Not dispatcher Is Nothing Then
                Return dispatcher.CheckAccess()
            Else
                Return True
            End If
        End Function

        Friend Sub DetachFromDispatcher()
            Me._dispatcher = Nothing
        End Sub

        Public Sub VerifyAccess()
            Dim dispatcher As Dispatcher = Me._dispatcher
            If (Not dispatcher Is Nothing) Then
                dispatcher.VerifyAccess()
            End If
        End Sub

    End Class

End Namespace